﻿using Microsoft.Xna.Framework;
using SaveTheQueen.Component;

namespace SaveTheQueen.Utils
{
    public static class Aling
    {
        public static Vector2 AlingSprite(Sprite toAlingObject, Sprite anchorObject, AnchorEdge edge, AnchorPoint point, float margin)
        {
            float x = 0, y = 0;
            switch (edge)
            {
                case (AnchorEdge.Left):
                    {
                        x = anchorObject.Position.X - toAlingObject.Size.X - margin;
                        switch (point)
                        {
                            case (AnchorPoint.Top):
                                {
                                    y = anchorObject.Position.Y;
                                    break;
                                }
                            case (AnchorPoint.Middle):
                                {
                                    y = anchorObject.Position.Y + (anchorObject.Size.Y / 2) - (toAlingObject.Size.Y / 2);
                                    break;
                                }
                            case (AnchorPoint.Botton):
                                {
                                    y = anchorObject.Position.Y + anchorObject.Size.Y - toAlingObject.Size.Y;
                                    break;
                                }
                        }
                        break;
                    }
                case (AnchorEdge.Up):
                    {
                        y = anchorObject.Position.Y - toAlingObject.Size.Y - margin;
                        switch (point)
                        {
                            case (AnchorPoint.Top):
                                {
                                    x = anchorObject.Position.X;
                                    break;
                                }
                            case (AnchorPoint.Middle):
                                {
                                    x = anchorObject.Position.X + (anchorObject.Size.X / 2) - (toAlingObject.Size.X / 2);
                                    break;
                                }
                            case (AnchorPoint.Botton):
                                {
                                    x = anchorObject.Position.X + anchorObject.Size.X - toAlingObject.Size.X;
                                    break;
                                }
                        }
                        break;
                    }
                case (AnchorEdge.Right):
                    {
                        x = anchorObject.Position.X + anchorObject.Size.X + margin;
                        switch (point)
                        {
                            case (AnchorPoint.Top):
                                {
                                    y = anchorObject.Position.Y;
                                    break;
                                }
                            case (AnchorPoint.Middle):
                                {
                                    y = anchorObject.Position.Y + (anchorObject.Size.Y / 2) - (toAlingObject.Size.Y / 2);
                                    break;
                                }
                            case (AnchorPoint.Botton):
                                {
                                    y = anchorObject.Position.Y + anchorObject.Size.Y - toAlingObject.Size.Y;
                                    break;
                                }
                        }
                        break;
                    }
                case (AnchorEdge.Down):
                    {
                        y = anchorObject.Position.Y + anchorObject.Size.Y + margin;
                        switch (point)
                        {
                            case (AnchorPoint.Top):
                                {
                                    x = anchorObject.Position.X;
                                    break;
                                }
                            case (AnchorPoint.Middle):
                                {
                                    x = anchorObject.Position.X + (anchorObject.Size.X / 2) - (toAlingObject.Size.X / 2);
                                    break;
                                }
                            case (AnchorPoint.Botton):
                                {
                                    x = anchorObject.Position.X + anchorObject.Size.X - toAlingObject.Size.X;
                                    break;
                                }
                        }
                        break;
                    }//endCase
            }//endSwitch
            return new Vector2(x, y);
        }
    }
}
